package com.hnevc.trafficdemotest1.fragment;

import android.app.AlertDialog;
import android.support.v4.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.hnevc.trafficdemotest1.R;
import com.hnevc.trafficdemotest1.dialog.RechargeDialog;


/**
 * Created by Administrator on 2018/1/1/001.
 */

public class AccountManagerFragment extends Fragment {

    private View view;
    private TextView mAccountMoney;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_account_manager, container, false);
        initView();
        initData();
        return view;
    }

    public AccountManagerFragment(){

    }
    private void initView() {

        ListView BusManagerlistView = (ListView)view.findViewById(R.id.Account_listView);
        MyBaseAdapter myBaseAdapter = new MyBaseAdapter();
        BusManagerlistView.setAdapter(myBaseAdapter);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


//        HashMap<String, String> map = new HashMap<String, String>();
//        map.put("carId", "");
//        map.put("username", "user2");
//        JSONObject object = new JSONObject(map);
//        String url = "http://192.168.1.142:8080/RestaurantServer/action/getCarAccountBalance.do";
//        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, object, new Response.Listener<JSONObject>() {
//            @Override
//            public void onResponse(JSONObject jsonObject) {
//                Gson gson = new Gson();
//                AccountManager money = gson.fromJson(jsonObject.toString(), AccountManager.class);
//                if ()
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError volleyError) {
//
//            }
//        });
//        RequestQueue requestQueue = newRequestQueue(getActivity());
//        requestQueue.add(request);
    }

    private void initData() {
    }

    class MyBaseAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public Object getItem(int position) {
            return getItemId(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            view = View.inflate(getActivity(), R.layout.account_manager_item, null);
            mAccountMoney = (TextView) view.findViewById(R.id.account_manager_tv);
            Button rechargeButton = (Button) view.findViewById(R.id.account_manager_bt);
            rechargeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RechargeDialog dialog = new RechargeDialog(getActivity());
                    dialog.setTitle("车辆账户充值");
                }
            });
            return convertView;
        }
    }
}
